package Terminal.UI;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class BarraNavigazione extends PanelComponent{

	private PanelLabel panellabeletichetta;
	private JLabel labeletichetta;
	private PanelLabel panellabelnavigazione;
	private JLabel labelnavigazione;
	private OptionPanelHorizzontal od;
	private PanelButton panelbuttonindietro;
	private JButton buttonindietro;
	private PanelButton panelbuttonlogout;
	private JButton buttonlogout;
	private PannelliAffiancatiHorizzontal pah;
	
	
	
	public BarraNavigazione(PanelComponent parent)
	{
		super(parent);
		this.labeletichetta = new JLabel(" ");
		this.labelnavigazione = new JLabel(" ");
		this.buttonindietro = new JButton("indietro");
		this.buttonlogout = new JButton("logout");
	}
	
	public BarraNavigazione(PanelComponent parent,JLabel labeletichetta, JLabel labelnavigazione, JButton buttonindietro, JButton buttonlogout)
	{
		super(parent);
		this.labeletichetta = labeletichetta;
		this.labeletichetta.setPreferredSize(new Dimension(150, 50));
		this.labeletichetta.setFont(new Font(this.labeletichetta.getFont().getName(), Font.BOLD, 18));
		this.labelnavigazione = labelnavigazione;
		this.labelnavigazione.setPreferredSize(new Dimension(600,50));
		this.labelnavigazione.setFont(new Font(this.labelnavigazione.getFont().getName(), Font.ITALIC, 16));
		this.buttonindietro = buttonindietro;
	//	this.buttonindietro.setFont(new Font(this.buttonindietro.getFont().getName(), Font.PLAIN, 16));
		this.buttonlogout = buttonlogout;
	//	this.buttonlogout.setFont(new Font(this.buttonlogout.getFont().getName(), Font.PLAIN, 16));
	}
	
	@Override
	public JPanel createComponents() {
		pannellocomponente= new JPanel(null);
		panelbuttonindietro = new PanelButton(null,buttonindietro);
		panelbuttonlogout = new PanelButton(null,buttonlogout);
		
		panellabeletichetta = new PanelLabel(null,labeletichetta);
		
		panellabelnavigazione = new PanelLabel(null,labelnavigazione);
		
		pah = new PannelliAffiancatiHorizzontal(null);
		panellabelnavigazione.setParent(pah);
		pah.addPosition(panellabeletichetta, 50);
/*0*/	pah.addPosition(panellabelnavigazione, 200);
		//label.setSize(200, 50);
		
		
		od= new OptionPanelHorizzontal(null);
		panelbuttonindietro.setParent(od);
		panelbuttonlogout.setParent(od);
/*1*/	od.addPosition(panelbuttonindietro, 0);
		od.addPosition(panelbuttonlogout, 100);
		od.setSize(od.getSize().width,50);
		od.setParent(pah);
		//od.setSize(width, height)
		pah.addPosition(od,1000);

		
		add(pah);
		pannellocomponente.add(pah.createComponents());
		JPanel paneltemp1=pah.createComponents();
		paneltemp1.setBackground(Color.white);
		
		setSize(pah.getSize());

		

		
		pannellocomponente.setBackground(Color.white);
		return pannellocomponente;
	}
	

	public void updateSize(){
		size_width=0;
		size_height=0;
		Dimension d= new Dimension(size_width,size_height);
		/*for (Map.Entry<String, PanelComponent> pcelement: children.entrySet()) {
			d=pcelement.getValue().getSize();
			size_width=size_width+d.width;
			if(size_height<d.height){size_height=d.height;}
		}*/
		for (PanelComponent pcelement: children) {
			d=pcelement.getSize();
			size_width=size_width+d.width;
			if(size_height<d.height){size_height=d.height;}
		if(parent!=null)parent.updateSize();
		}
	}
	

	

}
